package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JSONResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"permission:view","权限页面"},logical= Logical.OR)
    public String view() {
        return "permission";
    }
 
    @RequestMapping("reload")
    @ResponseBody
    public JSONResult reload() {
        try {
            permissionService.reload();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"重定向失败");
        }
        return  new JSONResult(true,"重定向成功");
    }
    @RequestMapping("getAll")
    @ResponseBody
    public List<Permission> getAll() {

        return permissionService.selectAll();

    }

    @RequestMapping("selectByRoleId")
    @ResponseBody
    public List<Permission> selectByRoleId(Long roleId) {
        return permissionService.selectByRoleId(roleId);
    }
}
